home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / lib / mntlib44.zoo / mntlib / calloc.c < prev    next >
C/C++ Source or Header  |  1993-07-06  |  892b  |  39 lines

  1. /* from the TOS GCC library */
  2. /* malloc, free, realloc: dynamic memory allocation */
  3. /* 5/2/92 sb -- modified for Heat-n-Serve C to accomodate its 16-bit size_t */
  4. /* 5/5/92 sb -- calloc() gets its own file to reduce library drag */
  5.  
  6. #include <compiler.h>
  7. #include <stddef.h>    /* for size_t */
  8. #include <memory.h>
  9. #include <string.h>
  10.  
  11. __EXTERN void *_malloc __PROTO((unsigned long));
  12. __EXTERN void _bzero __PROTO((void *, unsigned long));
  13. __EXTERN void *_calloc __PROTO((unsigned long, unsigned long));
  14.  
  15. #ifdef __GNUC__
  16. asm(".stabs \"_calloc\",5,0,0,__calloc"); /* dept of clean tricks */
  17. #endif
  18.  
  19. void * _calloc(n, sz)
  20. unsigned long n, sz;
  21. {
  22.   void *r;
  23.   unsigned long total;
  24.  
  25.   total = n * sz;
  26.   if ((r = _malloc(total)) != NULL) {
  27.     _bzero(r, total);
  28.   }
  29.   return(r);
  30. }
  31.  
  32. #ifndef __GNUC__
  33. void * calloc(n, sz)
  34. size_t n, sz;
  35. {
  36.   return _calloc((unsigned long) n, (unsigned long) sz);
  37. }
  38. #endif
  39.